import {tap} from 'rxjs/operators';
import {Injectable} from '@angular/core';
import {HttpEvent, HttpHandler, HttpHeaders, HttpInterceptor, HttpRequest, HttpResponse} from '@angular/common/http';
import {Observable} from 'rxjs';
import {Logger} from './logger';

@Injectable()
export class DefaultHttpInterceptor implements HttpInterceptor {
  readonly tagStyle = 'color:#3F97F9';
  readonly defaultTextStyle = 'color:#000000';

  constructor() {

  }

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // Logger.logWithParams(`%c[Request] %c${req.urlWithParams}`, this.tagStyle, this.defaultTextStyle);
    // const httpRequest = req.clone({
    //   headers: new HttpHeaders({
    //     'Cache-Control': 'no-cache, no-store, must-revalidate, post-check=0, pre-check=0',
    //     'Pragma': 'no-cache',
    //     'Expires': '0'
    //   })
    // });

    return next.handle(req).pipe(
      tap(event => {
        if (event instanceof HttpResponse) {
          // Logger.logWithParams(`%c[Response] %cof request: ${req.urlWithParams}\n${JSON.stringify(event.body)}`,
          //   this.tagStyle, this.defaultTextStyle);
        }
      }));
  }
}
